module Text ( Txt
            , StrictTxt
            , module Data.ByteString.Lazy.UTF8
            , Char8.unlines
            , Char8.words
            , Char8.unwords
            , Char8.append
            , Char8.concat
            , Char8.null
            , Char8.readInt

            , BS.getContents
            , BS.readFile
            , BS.writeFile
            , BS.putStr
            , BS.putStrLn
            , BS.interact
            , BS.hPutStr

            , map
            , all
            , show
            , read
            , reverse
            , normalize
            , toStrict
            , fromStrict
            , takeWhile
            , dropWhile
            , isPrefixOf
            , isSuffixOf
            , splitOn
            )
where
import Data.ByteString.Lazy.UTF8
import qualified Data.ByteString.Lazy.Char8 as Char8
import qualified Data.ByteString.Lazy as BS
import qualified Data.ByteString.Char8 as Strict 
import Prelude hiding (show,reverse,map,read,takeWhile,dropWhile,break,all)
import qualified Prelude
import qualified Utils 

type Txt = ByteString
type StrictTxt = Strict.ByteString

show :: (Show a) => a -> Txt
show = fromString . Prelude.show

read :: (Read a) => Txt -> a
read = Prelude.read . toString

reverse :: Txt -> Txt
reverse = fromString . Prelude.reverse . toString

map :: (Char -> Char) -> Txt -> Txt
map f = fromString . Prelude.map f . toString  -- FIXME

all :: (Char -> Bool) -> Txt -> Bool
all f = Prelude.all f . toString

normalize :: Txt -> Txt
normalize = Char8.fromChunks . return . Strict.concat . Char8.toChunks

toStrict :: Txt -> StrictTxt
toStrict = Strict.concat . Char8.toChunks

fromStrict :: StrictTxt -> Txt
fromStrict = Char8.fromChunks . return

takeWhile :: (Char -> Bool) -> Txt -> Txt
takeWhile f = fst . break (not . f)

dropWhile :: (Char -> Bool) -> Txt -> Txt
dropWhile f = snd . break (not . f)

isPrefixOf :: Txt -> Txt -> Bool
xs `isPrefixOf` ys = Prelude.all id . Char8.zipWith (==) xs $ ys

isSuffixOf :: Txt -> Txt -> Bool
xs `isSuffixOf` ys =  reverse xs `isPrefixOf` Char8.reverse ys


splitOn :: Char -> Txt -> [Txt]
splitOn c = Prelude.map fromString . Utils.splitOn c . toString

